﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Y2M.Components
{
    public class DownloadingList
    {
        #region singleton
        private static DownloadingList _instance;

        public static DownloadingList Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new DownloadingList();
                return _instance;
            }
        }

        private DownloadingList()
        {
        }
        #endregion

        private const string FileName = "downloading_list.bin";

        private List<string> _list = new List<string>();

        public void Add(string url)
        {
            if (_list.Contains(url))
                return;

            _list.Add(url);

            LocalStorage.SerializeToFile(FileName, _list);
        }

        public void Remove(string url)
        {
            _list.Remove(url);

            LocalStorage.SerializeToFile(FileName, _list);
        }

        public List<string> Get()
        {
            _list = LocalStorage.DeserializeFromFile<List<string>>(FileName);

            if (_list == null)
                _list = new List<string>();

            return _list;
        }
    }
}
